package com.zm.zyz.servlet;

import com.zm.zyz.entity.ZyzUser;
import com.zm.zyz.service.BizException;
import com.zm.zyz.service.ZyzBiz;
import com.zm.zyz.util.Utils;
import com.zm.zyz.vo.Result;
import org.apache.commons.lang3.mutable.MutableInt;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/join")
public class JoinsServlet extends HttpServlet {
    ZyzBiz biz = new ZyzBiz();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ZyzUser user = (ZyzUser) req.getSession().getAttribute("loginedUser");
        if (user == null){
            Utils.print(resp,new Result(0,"请先登录",null));
           return;
        }
        Integer uid = user.getId();
        String tid = req.getParameter("tid");
        try {
            biz.join(tid,uid);
            Utils.print(resp,new Result(1,"加入成功！",null));
        } catch (BizException e) {
            Utils.print(resp,new Result(-1,e.getMessage(),null));
        }catch (Exception e){
            Utils.print(resp,new Result(-2,"系统异常，请联系管理员",null));
        }
    }
}
